<?php

/**
 * Format Class
 *
 * @package default
 * @author Kevin Labesse
 **/
class FormatHelper extends Helper
{
	/**
	 * buildUsrArr transforms the array given in parameter to match an array given in a select for users.
	 *
	 * @param array $arr name of the array to modify
	 * @return array
	 * @author Kévin Labesse 
	 */
	function buildUsrArr($arr){
		if (!$arr)
			return null;
		foreach ($arr as $key):
			$res[$key['User']['id']] = $key['User']['lastname'].' '.$key['User']['firstname'];
		endforeach;
		return $res;
	}
	
	/**
	 * buildClientArr transforms the array given in parameter to match an array given in a select for companies.
	 *
	 * @param array $arr name of the array to modify
	 * @return array 
	 * @author Kévin Labesse 	 
	 */
	function buildClientArr($arr){
		if (!$arr)
			return null;
		foreach ($arr as $key):
			$res[$key['Company']['id']] = $key['Company']['name']; 
		endforeach;
		return $res;
	}
	
	/**
	 * buildContractArr transforms the array given in parameter to match an array given in a select for contract.
	 *
	 * @param array $arr name of the array to modify
	 * @return array 
	 * @author Kévin Labesse
	 */
	function buildContractArr($arr){
		if (!$arr)
			return null;
		foreach ($arr as $key):
			$res[$key['Contract']['id']] = $key['Contract']['ref']; 
		endforeach;
		return $res;
	}
	
	/**
	 * buildStatusArr transforms the array given in parameter to match an array given in a select for status.
	 *
	 * @param array $arr name of the array to modify
	 * @return array 
	 * @author Romain Venturi 	 
	 */
	function buildStatusArr($arr){
		foreach ($arr as $key) {
			$res[$key['Status']['id']] = $key['Status']['name']; 
		}
		return $res;
	}

	/**
	 * buildProjectArr transforms the array given in parameter to match an array given in a select for project.
	 *
	 * @param array $arr name of the array to modify
	 * @return array 
	 * @author Romain Venturi 	 
	 */
	function buildProjectArr($arr){
		foreach ($arr as $key) {
			$res[$key['Project']['id']] = $key['Project']['name']; 
		}
		return $res;
	}

	/**
	 * getUsersMailAdress returns mails of the users given in parameter.
	 *
	 * @param array $users name of the array which contains users mails
	 * @return string 
	 * @author Romain Venturi 	 
	 */
	function getUsersMailAdress($users, $company){
		$res = "";
		foreach ($users as $currentUser) {
			if ($currentUser['User']['Company']['name'] == $company) {
				$res .= $currentUser['User']['mail'].";";
			}
		}
		$res{strlen($res)-1} = ' ';
		return $res;
	}

	/**
	 * Function used to associate milestone string to milestone id
	 *
	 * @return int
	 * @author Rémi Peron
	 **/
	function getEnumMilestone($milestone)
	{
		switch ($milestone) {
			case 'to qualify':
				return 0;
			case 'in process':
				return 1;
			case 'idle':
				return 2;
			case 'idle client':
				return 3;
			case 'closed':
				return 4;
			default:
				return 0;
		}
	}
} // END class FormatHelper extends Helper
?>